package timing.ukulele.flow.service;

import timing.ukulele.flow.net.FlowUserInfoApi;
import timing.ukulele.flow.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import timing.ukulele.flow.vo.*;

import java.util.List;

/**
 * @ClassName FlowUserInfoService
 * @Description TODO
 * @Author 30621
 * @Date 2021/2/23 15:21
 * @Version 1.0
 **/
@Service
@Slf4j
public class FlowUserInfoService {

    @Autowired
    private FlowUserInfoApi flowUserInfoApi;

    public AreaVO getAreaTree(String parentcode) {
        Result<AreaVO> areaList = flowUserInfoApi.getAreaTree(parentcode);
        return areaList.getMessage();
    }

    public DeptmentVO getDepTree(String parentcode) {
        Result<DeptmentVO> depTree = flowUserInfoApi.getDepTree(parentcode);
        return depTree.getMessage();
    }

    public List<RoleVO> getRoleList(String name) {
        Result<List<RoleVO>> roleList = flowUserInfoApi.getRoleList(name);
        return roleList.getMessage();
    }

    public List<RuleVO> getFlowRuleList() {
        Result<List<RuleVO>> flowRuleList = flowUserInfoApi.getFlowRuleList();
        return flowRuleList.getMessage();
    }

    public List<UserVO> getUserList(String userpara, String uuid, String depcode, String areacode, String roles, String isand,
                                    String usertype, String startuser, String flowuser, String rulecode) {
        if (!(StringUtils.isEmpty(userpara) ||
                StringUtils.isEmpty(uuid) ||
                StringUtils.isEmpty(depcode) ||
                StringUtils.isEmpty(areacode) ||
                StringUtils.isEmpty(roles) ||
                StringUtils.isEmpty(isand) ||
                StringUtils.isEmpty(usertype))
        ) {
            return null;
        }
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("userpara=").append(userpara)
                .append(",uuid=").append(uuid)
                .append(",depcode=").append(depcode)
                .append(",areacode=").append(areacode)
                .append(",roles=").append(roles)
                .append(",isand=").append(isand)
                .append(",usertype=").append(usertype)
                .append(",rulecode=").append(rulecode);
        log.info("当前使用的参数为：" + stringBuffer.toString());
        Result<List<UserVO>> userList = flowUserInfoApi.getUserList(userpara, uuid, depcode, areacode, roles, isand, usertype,
                startuser, flowuser, rulecode);
        return userList.getMessage();
    }

}
